package org.linlinjava.litemall.admin.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.dao.TGoodsMapper;
import org.linlinjava.litemall.db.dao.TOrderMapper;
import org.linlinjava.litemall.db.dao.TShopMapper;
import org.linlinjava.litemall.db.dao.TUser2Mapper;
import org.linlinjava.litemall.db.domain.TGoodsExample;
import org.linlinjava.litemall.db.domain.TOrderExample;
import org.linlinjava.litemall.db.domain.TShopExample;
import org.linlinjava.litemall.db.domain.TUser2Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/dashboard")
@Validated
public class AdminDashbordController {
    private final Log logger = LogFactory.getLog(AdminDashbordController.class);

    @GetMapping("")
    public Object info() {
        long userTotal = user2Mapper.countByExample(TUser2Example.newAndCreateCriteria().example());

        long goodsTotal = goodsMapper.countByExample(TGoodsExample.newAndCreateCriteria().andDeletedEqualTo(Boolean.FALSE).example());

        long orderTotal = orderMapper.countByExample(TOrderExample.newAndCreateCriteria().example());

        long groupTotal = shopMapper.countByExample(TShopExample.newAndCreateCriteria().example());


        Map<String, Object> data = new HashMap<>();
        data.put("userTotal", userTotal);
        data.put("goodsTotal", goodsTotal);
        data.put("orderTotal", orderTotal);
        data.put("groupTotal", groupTotal);

        return ResponseUtil.ok(data);
    }

    @Autowired
    private TUser2Mapper user2Mapper;
    @Autowired
    private TGoodsMapper goodsMapper;
    @Autowired
    private TOrderMapper orderMapper;
    @Autowired
    private TShopMapper shopMapper;


}
